 let ruleArrs = [
         //【AAA+】
         { regexp: /(\d)\1{2,}/g, type: 1, price: 2800 },
         //【AABB】
         { regexp: /(((\d)\3){2,})/g, type: 2, price: 1800 },
         //【ABAB+】
         { regexp: /(\d)((?!\1)\d)(\1\2){1,}/g, type: 3, price: 1600 },
         //重复出现5次以上
         { regexp: /(\d)((\d*)\1){4,}/g, type: 4, price: 1500 },
         //【爱情号】
         { regexp: /520|1314/g, type: 5, price: 1500 },
         //【ABC】【CBA】
         {
             regexp: /((?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){2,}\d)|((?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){2,}\d)/g,
             type: 6,
             price: 600,
         },
         //【ABAA】【AABA】
         {
             regexp: /((\d)((?!\2)\d)\2\2)|((\d)\5((?!\5)\d)\5)/g,
             type: 7,
             price: 500,
         },
         //【发财号】
         {
             regexp: /668|886|688|618|168|188|518|1588|918/g,
             type: 8,
             price: 500,
         },
         //ABDBA
         { regexp: /((\d)((?!\2)\d)((?!\3)\d)\3\2)/g, type: 9, price: 400 },
         //ABDAB
         { regexp: /((\d)((?!\2)\d)((?!\3)\d)\2\3)/g, type: 10, price: 400 },
         //ABBA
         { regexp: /((\d)((?!\2)\d)\3\2)/g, type: 11, price: 400 },
         //【AA】
         { regexp: /(\d)\1{1}/g, type: 12, price: 200 },
         //【2个6、2个8】
         { regexp: /(6)(\d*)\1/g, type: 13, price: 200 },
         { regexp: /(8)(\d*)\1/g, type: 14, price: 200 },
         //ABCDABC
         {
             regexp: /((\d)((?!\2)\d)((?!\2)(?!\3)\d))(\d+)\1/g,
             type: 15,
             price: 400,
         },
         //ABCDCBA
         {
             regexp: /((\d)((?!\2)\d)((?!\2)(?!\3)\d))(\d+)\4\3\2/g,
             type: 16,
             price: 400,
         },
         //ABCABC
         { regexp: /((\d)((?!\2)\d)((?!\2)(?!\3)\d))\1/g, type: 17, price: 400 },
         //ABCCBA
         {
             regexp: /(\d)((?!\1)\d)((?!\1)(?!\2)\d)\3\2\1/g,
             type: 18,
             price: 400,
         },
     ]
     /**
      * 校验过滤的号码
      * @param {*} sourcePhone
      * @param {*} rule
      * @param {*} typeArr
      * @param {*} lhArr
      */
 function getFilterPhone(sourcePhone, rule, typeArr, lhArr, numberKeyword) {
     //  console.log(123);
     var type = rule.type;
     var isSuccess = false;
     var price = 0;
     var rs;
     while ((rs = rule.regexp.exec(sourcePhone)) != null) {
         if (rs) {
             isSuccess = true;
             //匹配的第一个下标
             var index = rs.index;
             //匹配的字符串
             var keyStr = rs[0];
             //中间间隔开的数字标蓝
             if (type == 9 || type == 10) {
                 lhArr[index] = 0;
                 lhArr[index + 1] = 0;
                 var betweenFlag = lhArr[index + 2];
                 if (betweenFlag != 0) {
                     lhArr[index + 2] = 2;
                 }
                 lhArr[index + 3] = 0;
                 lhArr[index + 4] = 0;
                 //2个6、8；4/5个重复以上数字
             } else if (type == 4 || type == 7 || type == 13 || type == 14) {
                 var keyFlag = keyStr.charAt(0);
                 var keyArr = keyStr.split("");
                 for (var k = 0; k < keyArr.length; k++) {
                     if (keyArr[k] == keyFlag) {
                         lhArr[k + index] = 0;
                     }
                 }
             } else {
                 for (var k = index; k < index + keyStr.length; k++) {
                     lhArr[k] = 0;
                 }
             }
         }
     }
     if (isSuccess && typeArr.indexOf(type) == -1) {
         typeArr.push(rule.type);
         price += rule.price;
     }
     if (numberKeyword) {
         var indexKey = sourcePhone.indexOf(numberKeyword);
         if (indexKey || indexKey == 0) {
             for (
                 var index = indexKey; index < indexKey + numberKeyword.length; index++
             ) {
                 lhArr[index] = 2;
             }
         }
     }
     //   console.log(price);
     return price;
 }
 // 数组中匹配单个字符串的方法，传入数组支持格式[{},{}],
 //  function searchStr(str, arr) {
 //     let newList = [];
 //     // 要匹配字符串的首个字符
 //     let startChar = str.charAt(0);
 //     // 要匹配字符串的字符长度
 //     let strLength = str.length;
 //     for (let i = 0; i < arr.length; i++) {
 //       // 默认数组arr中对象arr[i]不存在str
 //       let isExist = false;
 //       let obj = arr[i];

 //       for (let key in obj) {
 //         if (typeof obj[key] === "function") {
 //           obj[key]();
 //         } else {
 //           let keyValue = "";
 //           // 获取arr[i][key]的值
 //           if (obj[key] !== null && typeof obj[key] === "string") {
 //             keyValue = obj[key];
 //           } else if (obj[key] !== null && typeof obj[key] !== "string") {
 //             keyValue = JSON.stringify(obj[key]);
 //           }
 //           // arr[i][key]中的各个位置的字符与str的0位置字符startChar对比如果相等，
 //           // 在arr[i][key]中从j位置截取与str长度相同的字符，对比是否相等
 //           for (let j = 0; j < keyValue.length; j++) {
 //             // 把原有数据转化为小写，输入数据也转化为纯小写，实现模糊匹配,如区分大小写，可删除toLowerCase()

 //             if (
 //               keyValue.charAt(j).toLowerCase() === startChar.toLowerCase()
 //             ) {
 //               if (
 //                 keyValue
 //                   .substring(j)
 //                   .substring(0, strLength)
 //                   .toLowerCase() === str.toLowerCase()
 //               ) {
 //                 // 模糊匹配到的字符存在表示arr[i]中存在str
 //                 isExist = true;
 //                 break;
 //               }
 //             }
 //           }
 //         }
 //       }
 //       // 当arr[i]中存在str时，把arr[i]放入一个新数组
 //       if (isExist === true) {
 //         newList.push(obj);
 //       }
 //     }
 //     // 最后返回这个新数组
 //     return newList;
 //   }
 function filterPhoneNumberLists(lists, type, numberKeyword) {

     if (!lists ||
         Object.prototype.toString.call(lists) !== "[object Array]"
     ) {
         return [];
     }
     if (lists.length <= 0) {
         return [];
     }
     type = type || 0;
     var filterList = [];
     for (var i = 0; i < lists.length; i++) {
         var filterPhone = {};
         //靓号标记数组，0=红色；1=黑色；2=蓝色
         var lhArr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
         var typeArr = [];
         var priceCount = 0;

         let ruleArr = ruleArrs;
         //靓号过滤
         var sourcePhone = lists[i];
         var ruleCount = 0;

         if (type > 0) {
             sourcePhone
             //修改，其他靓号规则一起打标记
             //  匹配固定的规则
             var curCount = getFilterPhone(
                 sourcePhone,
                 ruleArr[type - 1],
                 typeArr,
                 lhArr,
                 numberKeyword
             );

             priceCount += curCount;
             if (curCount > 0) {
                 ruleCount++;
             }
         } else {
             for (var j = 0; j < ruleArr.length; j++) {
                 var curCount = getFilterPhone(
                     sourcePhone,
                     ruleArr[j],
                     typeArr,
                     lhArr,
                     numberKeyword
                 );
                 priceCount += curCount;
                 if (curCount > 0) {
                     ruleCount++;
                     if (ruleCount >= 2) {
                         break;
                     }
                 }
             }
         }
         if ((type > 0 && priceCount > 0) || type <= 0) {
             filterPhone.phone = sourcePhone;
             filterPhone.type = typeArr;
             filterPhone.lhArr = lhArr;
             if (priceCount > 0) {
                 priceCount += 88;
             }
             filterPhone.priceCount = priceCount;
             filterList.push(filterPhone);
         }
     }
     filterList.sort(function(a, b) {
         return b.priceCount - a.priceCount;
     });
     if (filterList && filterList.length > 0 && numberKeyword) {
         var endList = filterList.filter(
             (item) => item.phone && item.phone.endsWith(numberKeyword)
         );
         var otheList = filterList.filter(
             (item) => item.phone && !item.phone.endsWith(numberKeyword)
         );
         endList = endList.concat(otheList);
         return endList;
     }

     return filterList;
 }

 function chineseLen(txt) {
     var n = 0;
     var len = txt.length;
     for (var i = 0; i < len; i += 1) {
         if (
             /[\u4E00-\u9FA5\u3400-\u4DB5\u9FA6-\u9FBB\uF900-\uFA2D\uFA30-\uFA6A\uFA70-\uFAD9]/.test(
                 txt.charAt(i)
             )
         ) {
             n += 1;
         }
     }
     return n;
 }

 function checkScript(text) {
     var flag = false;
     var scriptWord = "<|>|script|alert|{|}|#|$|'|\"|:|;|&|*|@|@|%|^|?";
     var words = scriptWord.split("|");
     for (var i = 0; i < words.length; i += 1) {
         if (text.indexOf(words[i]) !== -1) {
             flag = true;
             break;
         }
     }
     return flag;
 }

 function checkCard(idcard) {
     var area = {
         11: "北京",
         12: "天津",
         13: "河北",
         14: "山西",
         15: "内蒙古",
         21: "辽宁",
         22: "吉林",
         23: "黑龙江",
         31: "上海",
         32: "江苏",
         33: "浙江",
         34: "安徽",
         35: "福建",
         36: "江西",
         37: "山东",
         41: "河南",
         42: "湖北",
         43: "湖南",
         44: "广东",
         45: "广西",
         46: "海南",
         50: "重庆",
         51: "四川",
         52: "贵州",
         53: "云南",
         54: "西藏",
         61: "陕西",
         62: "甘肃",
         63: "青海",
         64: "宁夏",
         65: "新疆",
         71: "台湾",
         81: "香港",
         82: "澳门",
         91: "国外",
     };
     var Y, JYM, S, M;
     var idcard_array = idcard.split("");
     //地区检验
     if (area[parseInt(idcard.substr(0, 2))] === null) {
         return false;
     }
     //身份号码位数及格式检验
     switch (idcard.length) {
         case 18:
             //18位身份号码检测
             //出生日期的合法性检查
             //闰年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))
             //平年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))
             var ereg;
             if (
                 parseInt(idcard.substr(6, 4)) % 4 === 0 ||
                 (parseInt(idcard.substr(6, 4)) % 100 === 0 &&
                     parseInt(idcard.substr(6, 4)) % 4 === 0)
             ) {
                 ereg = /^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/; //闰年出生日期的合法性正则表达式
             } else {
                 ereg = /^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/; //平年出生日期的合法性正则表达式
             }
             if (ereg.test(idcard)) {
                 //测试出生日期的合法性
                 //计算校验位
                 S =
                     (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7 +
                     (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9 +
                     (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10 +
                     (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5 +
                     (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8 +
                     (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4 +
                     (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2 +
                     parseInt(idcard_array[7]) +
                     parseInt(idcard_array[8]) * 6 +
                     parseInt(idcard_array[9]) * 3;
                 Y = S % 11;
                 M = "F";
                 JYM = "10X98765432";
                 M = JYM.substr(Y, 1);
                 if (M == idcard_array[17].toUpperCase()) {
                     return true;
                 } else {
                     return false;
                 }
             } else {
                 return false;
             }
             break;
         default:
             return false;
             break;
     }
 }

 function checkCardAge(idcard) {
     var date = new Date();
     var year = date.getFullYear();
     var month = date.getMonth() + 1;
     var strDate = date.getDate();

     var idYear = parseInt(idcard.substr(6, 4)); //身份证年
     var idMonth = parseInt(idcard.substr(10, 2)); //身份证月
     var idDate = parseInt(idcard.substr(12, 2)); //身份证日

     if (year - idYear > 16) {
         return true;
     } else if (year - idYear === 16) {
         if (month > idMonth) {
             return true;
         } else if (month == idMonth && strDate >= idDate) {
             return true;
         }
     }
     return false;
 }

 function checkCardAgeUpperLimit(idcard, maxAge) {
     var date = new Date();
     var year = date.getFullYear();
     var month = date.getMonth() + 1;
     var strDate = date.getDate();

     var idYear = parseInt(idcard.substr(6, 4)); //身份证年
     var idMonth = parseInt(idcard.substr(10, 2)); //身份证月
     var idDate = parseInt(idcard.substr(12, 2)); //身份证日

     if (year - idYear > maxAge) {
         return true;
     } else if (year - idYear === maxAge) {
         if (month > idMonth) {
             return true;
         } else if (month == idMonth && strDate >= idDate) {
             return true;
         }
     }
     return false;
 }
 export default {
     getFilterPhone,
     filterPhoneNumberLists,
     chineseLen,
     checkScript,
     checkCard,
     checkCardAge,
     checkCardAgeUpperLimit
 }